package com.vip.service.admin.impl;

import com.vip.dao.admin.dao.UserDao;
import com.vip.dao.admin.domain.User;
import com.vip.service.admin.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;


    @Override
    public User findUserById(Long id) {
        return userDao.findById(id).get();
    }

    @Override
    public User addUser(User user) {
        return userDao.save(user);
    }

    @Override
    public User findUserByUserName(String userName) {
        return userDao.findUserByUserName(userName);
    }

    @Override
    public User findUserByUserNameAndPassword(String userName, String passWord) {
        return userDao.findUserByUserNameAndPassWord(userName,passWord);
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public Page<User> findAlluser(int page, int size){
        Pageable pageable = PageRequest.of(page,size);
        Page<User> userPage = userDao.findAll(pageable);
        return userPage;
    }

    @Override
    public void deleteUserById(Long id) {
        userDao.deleteById(id);
    }
}
